package com.xiaoyu.lanling.feature.serverpush.event

import `in`.srain.cube.request.JsonData
import com.xiaoyu.base.data.UserData
import com.xiaoyu.base.data.UserInfoDataProvider
import com.xiaoyu.base.model.User
import com.xiaoyu.base.serverpush.event.ServerPushBaseEvent
import com.xiaoyu.lanling.event.user.UserExtraUpdateEvent
import com.xiaoyu.lanling.feature.user.model.UserExtra

class AppUserUpdatePush(val jsonData: JsonData) : ServerPushBaseEvent(jsonData) {

    override fun takeAction() {
        setComplete()
        val userJsonData = jsonData.optJson("user")
        UserData.getInstance().tryUpdateSelf(userJsonData)
        UserInfoDataProvider.getInstance().updateUser(User.fromJson(userJsonData))
        UserExtra.instance.updateAndSave(userJsonData)
        UserExtraUpdateEvent().post()
    }
}